import common
import pymysql

conn = common.get_conn(database='school',
                       cursorclass=pymysql.cursors.DictCursor)
try:
    with conn.cursor() as cursor:
        cursor.execute('select * from tb_student')
        # cursor.fetchone() - 抓取一条记录 -> tuple
        # cursor.fetchmany(n) - 抓取多条记录 -> tuple(tuple)
        # cursor.fetchall() - 抓取所有记录 -> tuple(tuple)
        student = cursor.fetchone()
        print(student['stuname'], student['stubirth'])
        print('-' * 100)
        print(cursor.fetchone())
        print('-' * 100)
        print(cursor.fetchmany(2))
        print('-' * 100)
        print(cursor.fetchall())
except pymysql.MySQLError as err:
    print(err)
finally:
    conn.close()
